package com.burstly.lib.network.beans.cookie;

import com.burstly.lib.util.LoggerExt;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public final class MemoryCookieStorage
  implements ICookieStorage
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "MemoryCookieStorage";
  private final Map<String, CookieHolderWrapper> mCookies = new HashMap(66);
  private final Object mLock = new Object();

  public MemoryCookieStorage(Collection<CookieHolderWrapper> paramCollection)
  {
    if ((paramCollection != null) && (!paramCollection.isEmpty()))
    {
      Iterator localIterator = paramCollection.iterator();
      while (localIterator.hasNext())
      {
        CookieHolderWrapper localCookieHolderWrapper = (CookieHolderWrapper)localIterator.next();
        if (localCookieHolderWrapper != null)
          this.mCookies.put(localCookieHolderWrapper.getCookie().getName(), localCookieHolderWrapper);
      }
    }
    LOG.logDebug("MemoryCookieStorage", "Initialization completed.", new Object[0]);
  }

  private void deleteInvalidCookies()
  {
    long l = System.currentTimeMillis();
    if (!this.mCookies.isEmpty())
    {
      Iterator localIterator = this.mCookies.entrySet().iterator();
      while (localIterator.hasNext())
      {
        CookieHolderWrapper localCookieHolderWrapper = (CookieHolderWrapper)((Map.Entry)localIterator.next()).getValue();
        if (localCookieHolderWrapper.getExpirationTime() < l)
        {
          LoggerExt localLoggerExt = LOG;
          Object[] arrayOfObject = new Object[2];
          arrayOfObject[0] = localCookieHolderWrapper.getCookie();
          arrayOfObject[1] = new Date(localCookieHolderWrapper.getExpirationTime());
          localLoggerExt.logDebug("MemoryCookieStorage", "Cookie expired: {0}. Expiration time: {1}", arrayOfObject);
          localIterator.remove();
        }
      }
    }
  }

  public void clear()
  {
    synchronized (this.mLock)
    {
      this.mCookies.clear();
      return;
    }
  }

  public void deleteCookie(String paramString)
  {
    if (paramString != null)
      synchronized (this.mLock)
      {
        this.mCookies.remove(paramString);
        return;
      }
  }

  public Collection<CookieHolderWrapper> getValidCookies()
  {
    synchronized (this.mLock)
    {
      deleteInvalidCookies();
      if (!this.mCookies.isEmpty())
      {
        ArrayList localArrayList = new ArrayList(this.mCookies.values());
        return localArrayList;
      }
      List localList = Collections.emptyList();
      return localList;
    }
  }

  public void processCookies(Collection<CookieHolder> paramCollection)
    throws Exception
  {
    if (paramCollection == null)
      throw new IllegalArgumentException("Cannot process null-referenced list of cookies.");
    if (paramCollection.isEmpty())
      return;
    synchronized (this.mLock)
    {
      Iterator localIterator = paramCollection.iterator();
      Object localObject5 = null;
      try
      {
        if (localIterator.hasNext())
        {
          CookieHolder localCookieHolder = (CookieHolder)localIterator.next();
          if (localCookieHolder != null)
          {
            localObject6 = new CookieHolderWrapper(localCookieHolder);
            if ((CookieHolderWrapper)this.mCookies.put(localCookieHolder.getName(), localObject6) != null)
            {
              LoggerExt localLoggerExt2 = LOG;
              Object[] arrayOfObject2 = new Object[2];
              arrayOfObject2[0] = localCookieHolder;
              arrayOfObject2[1] = new Date(((CookieHolderWrapper)localObject6).getExpirationTime());
              localLoggerExt2.logDebug("MemoryCookieStorage", "Cookie updated: {0}. Expiration time: {1}", arrayOfObject2);
              break label216;
            }
            LoggerExt localLoggerExt1 = LOG;
            Object[] arrayOfObject1 = new Object[2];
            arrayOfObject1[0] = localCookieHolder;
            arrayOfObject1[1] = new Date(((CookieHolderWrapper)localObject6).getExpirationTime());
            localLoggerExt1.logDebug("MemoryCookieStorage", "New cookie added: {0}. Expiration time: {1}", arrayOfObject1);
            break label216;
            label198: Object localObject2;
            throw localObject2;
          }
        }
        else
        {
          return;
        }
      }
      finally
      {
        break label198;
        Object localObject6 = localObject5;
        label216: localObject5 = localObject6;
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.network.beans.cookie.MemoryCookieStorage
 * JD-Core Version:    0.6.2
 */